package com.example.dbproto;

import java.sql.Date;
import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;

public class MainActivity extends Activity {

	Button btnOk,btnDay,btnPeriodSeat;
	DatePicker datePicker;
	
	DBHandler dbHandler;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        btnOk = (Button)findViewById(R.id.btnOK);
        btnDay = (Button) findViewById(R.id.btnDay);
        btnPeriodSeat = (Button) findViewById(R.id.btnPeriodSeat);
        datePicker = (DatePicker)findViewById(R.id.datePicker1);
        
        dbHandler = new DBHandler(this);
        
        btnOk.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Date date = new Date(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
				dbHandler.insertDaily(date,1,0,0,10,0);
				
				dbHandler.testDB();
			}
		});
        btnDay.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				Date date = new Date(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
				Alcohol alcol = dbHandler.getDayAlcohol(date);
				Log.e("debug","amount:"+alcol.amount+" bottle:"+alcol.sojuB);
			}
		});
        btnPeriodSeat.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				Date date = new Date(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
				Date ndate = new Date(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()+20);
				
				//Log.e("debug","period:"+dbHandler.getPeriodSeat(date, ndate));
				
//				Alcohol alcol = dbHandler.getPeriodAlcohol(date, ndate);
//				Log.e("debug","periodAmount:"+alcol.getAmount()+" bottle:"+alcol.getMakB());
				
				ArrayList<Alcohol> list = dbHandler.getListAlcohol(date, ndate);
				Log.e("debug","periodAmount:"+list.get(0).getAmount()+" bottle:"+list.get(0).getMakB());
				
			}
		});
        
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
